package org.example.seata.bs.account.controller;

import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.example.seata.bs.account.service.AccountEnhanceService;
import org.example.seata.bs.api.dto.account.AccountBalanceLogDto;
import org.example.seata.bs.api.entity.account.Account;
import org.example.seata.bs.api.vo.account.AccountBalanceLogVo;
import org.example.seata.bs.api.vo.account.AccountVo;
import org.example.seata.common.core.util.ApiResp;
import org.example.seata.common.security.config.resource.Inner;
import org.example.seata.common.security.util.SecurityUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author hzq
 * @date 2021/11/30 14:36
 */
@RestController
@RequestMapping("/account")
@AllArgsConstructor
public class AccountController {

    private final AccountEnhanceService accountEnhanceService;

    @PostMapping("/minusAccountBalance")
    @ApiOperation("减去账户余额")
    public ApiResp<AccountBalanceLogVo> minusAccountBalance(@RequestBody @Valid AccountBalanceLogDto dto) {
        return accountEnhanceService.minusAccountBalance(dto);
    }

    @GetMapping
    @ApiOperation("用户信息")
    public ApiResp<AccountVo> getInfo() {
        Account account = accountEnhanceService.getById(SecurityUtil.getAuth().getAccountId());
        AccountVo vo = new AccountVo();
        BeanUtils.copyProperties(account, vo);
        return ApiResp.ofSuccess(vo);
    }

    @Inner
    @PutMapping
    @ApiOperation("用户信息")
    public ApiResp putInfo() {
        return ApiResp.ofSuccessMessage("查询用户信息成功");
    }

}
